﻿using UnityEngine;
using System.Collections;
using LitJson;
using System;

public class XQCJsonData : JsonData
{
    private JsonData _root = new JsonData();
    public int ToInt()
    {
        return Convert.ToInt32(this.ToString());
    }
    public float ToFloat()
    {
        return Convert.ToSingle(this.ToString());
    }
    public Vector3 ToVector3()
    {
        if (this.IsExistKey("x") && this.IsExistKey("y") && this.IsExistKey("z"))
        {
            return new Vector3(this["x"].ToFloat(), this["y"].ToFloat(), this["z"].ToFloat());
        }
        else 
        {
            return new Vector3();
        }
        
    }
    public XQCJsonData this[int index]
    {
        get { return (XQCJsonData)_root[index]; }
        set { _root[index] = value; }
    }
    public XQCJsonData this[string prop_name] 
    {
        get { return (XQCJsonData)_root[prop_name]; }
        set { _root[prop_name] = value; }
    }
    public bool IsExistKey(string key)
    {
        try
        {
            var a = _root[key];
            return true;
        }
        catch
        {
            return false;
        }
    }
}
